<template>
  <div class="side">
    <div class="register">
      <el-row>
        <el-button type="primary" class="dakai" @click="createData">提交</el-button>
      </el-row>
    </div>
    <el-form :model="UserCenter" ref="dataForm" label-position="right" label-width="176px">
      <el-form-item label="用户中心">
        <el-radio-group v-model="UserCenter.status">
          <el-radio label="1">Discuz(Ucenter)</el-radio>
          <el-radio label="0">无</el-radio>
        </el-radio-group>
      </el-form-item>
      <div v-show="UserCenter.status==='1'">
        <el-form-item label="UserCenter配置">
          <a target="_blank" href="" style="color:#428bcb">如何配置？</a>
        </el-form-item>
        <el-form-item label="UC_CONNECT">
          <el-input v-model="UserCenter.ucConnect" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_DBHOST">
          <el-input v-model="UserCenter.ucDbHost" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_DBUSER">
          <el-input v-model="UserCenter.ucDbUser" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_DBPW">
          <el-input v-model="UserCenter.ucDbPw" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_DBNAME">
          <el-input v-model="UserCenter.ucDbName" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_DBCHARSET">
          <el-input v-model="UserCenter.ucDbCharset" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_DBTABLEPRE">
          <el-input v-model="UserCenter.ucDbTablePre" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_DBCONNECT">
          <el-input v-model="UserCenter.ucDbConnect" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_KEY">
          <el-input v-model="UserCenter.ucKey" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_API">
          <el-input v-model="UserCenter.ucApi" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_CHARSET">
          <el-input v-model="UserCenter.ucCharset" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_IP">
          <el-input v-model="UserCenter.ucIp" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_APPID">
          <el-input v-model="UserCenter.ucAppId" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="UC_PPP">
          <el-input v-model="UserCenter.ucPpp" placeholder="" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="过滤邮箱地址清单">
          <el-input
            type="textarea"
            :rows="4"
            style="width:600px;margin-top:10px;"
            v-model="UserCenter.email">
          </el-input>
        </el-form-item>
      </div>
      <!-- 说明 -->
      <div class="coot">
        <div>1.若通讯失败，注册和登录将提示输入不合法或通讯失败需管理员配置。</div>
        <div>2.通讯成功，Discuz所有注册用户，用户的用户名（需满足ES注册规则，否则无法同步）、密码、邮箱信息，无论通讯前还是通讯后注册都可以登录并同步到网站。</div>
        <div>3.通讯成功，只有通讯之后在ES注册的新用户，才能登录并同步到Discuz，通讯之前的注册用户，不能登录和同步。</div>
        <div>4.由于密码加密机制不同，Discuz的注册用户，无法批量导入到网站；网站的注册用户，也无法批量导入到Discuz。</div>
      </div>
    </el-form>
  </div>
</template>
<script>
  import {addUserCenterSet, getUserCenterSet} from '@/api/system/usercenter_set';
  import {getTenantId} from '@/utils/auth';

  export default {
    data() {
      return {
        UserCenter: {
          status: '',
          ucConnect: '',
          ucDbHost: '',
          ucDbUser: '',
          ucDbPw: '',
          ucDbName: '',
          ucDbCharset: '',
          ucDbTablePre: '',
          ucDbConnect: '',
          ucKey: '',
          ucApi: '',
          ucCharset: '',
          ucIp: '',
          ucAppId: '',
          ucPpp: '',
          email: ''
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getUserCenterSet(getTenantId()).then(response => {
          console.log(response)
          this.UserCenter = response.data
        }).catch(err => {
          console.log(err)
        })
      },
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.UserCenter.tenantId = getTenantId();
            addUserCenterSet(this.UserCenter).then(() => {
              this.$notify({
                title: '成功',
                message: '创建成功',
                type: 'success',
                duration: 2000
              });
              this.fetchData();
            })
          }
        })
      }
    }
  }
</script>

<style>

  .register {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #e7e9ed;
    padding-top: 15px;
    padding-right: 34px;
  }

  .dakai {
    float: right;
    position: absolute;
    right: 10px;
    bottom: -25px;
  }

  .coot {
    width: 800px;
    margin-top: 20px;
    margin-left: 6px;
    padding: 15px 15px;
    border-radius: 5px;
    background-color: #d9edf7;
    color: #326f8f;
    border-left: 5px solid #50bfff;
  }
</style>
